<template>
  <div class="app-container">
    <el-form :model="form" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="商铺编号" prop="payId">
        <el-select v-model="form.shopsId" placeholder="请选择商铺id">
          <el-option v-for="dict in shopList" :key="dict.id" :label="dict.code" :value="parseInt(dict.id)"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="getshops">搜索</el-button>
      </el-form-item>
    </el-form>
    <el-descriptions :column="3">
      <el-descriptions-item label="编号">{{ shop.code }}</el-descriptions-item>
      <el-descriptions-item label="商铺状态">{{
      shop.state
    }}</el-descriptions-item>
      <el-descriptions-item label="到期日期">{{
        rentalContract.endTime
      }}</el-descriptions-item>
      <el-descriptions-item label="占地面积">{{
        shop.floorArea
      }}</el-descriptions-item>
      <el-descriptions-item label="使用面积">{{
        shop.useArea
      }}</el-descriptions-item>
      <el-descriptions-item label="行业">{{
        rentalContract.trade
      }}</el-descriptions-item>
      <el-descriptions-item label="客户姓名">{{
        rentalContract.hirerName
      }}</el-descriptions-item>
      <el-descriptions-item label="联系方式">{{
        rentalContract.hirerPhone
      }}</el-descriptions-item>
      <el-descriptions-item label="入住时间">{{
        rentalContract.startTime
      }}</el-descriptions-item>
    </el-descriptions>
    <!-- 临时收费/押金弹出框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item  label="收费项目" prop="chargeitemId">
          <el-select :disabled =true v-model="form.chargeitemId" placeholder="请选择收费项目">
            <el-option
              :disabled =true
              v-for="dict in chargeitemList"
              :key="dict.id"
              :label="dict.name"
              :value="parseInt(dict.id)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item  label="收费金额" prop="money">
          <el-input :disabled =true v-model="form.money" placeholder="请输入收费金额" />
        </el-form-item>
        <el-form-item  label="付款方式" prop="payId">
          <el-select :disabled =true v-model="form.payId" placeholder="请选择付款方式">
            <el-option
              :disabled =true
              v-for="dict in Paymentmethod"
              :key="dict.id"
              :label="dict.name"
              :value="parseInt(dict.id)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="收款时间" prop="chargeTime">
          <el-date-picker clearable
            :disabled =true
            v-model="form.chargeTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择收款时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="退款时间" prop="refundTime">
          <el-date-picker clearable
            v-model="form.refundTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择退款时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="退款方式" prop="refundId">
          <el-select v-model="form.refundId" placeholder="请选择退款方式">
            <el-option

              v-for="dict in Paymentmethod"
              :key="dict.id"
              :label="dict.name"
              :value="parseInt(dict.id)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="chargeRemark">
          <el-input v-model="form.chargeRemark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 预存款弹出框 -->
    <el-dialog :title="title" :visible.sync="open1" width="600px" append-to-body>
      <el-form ref="form" :model="form1" :rules="rules" label-width="100px">
        <el-form-item  label="收费项目" prop="chargeitemId">
          <el-select :disabled =true v-model="form1.chargeitemId" placeholder="请选择收费项目">
            <el-option
              :disabled =true
              v-for="dict in chargeitemList"
              :key="dict.id"
              :label="dict.name"
              :value="parseInt(dict.id)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item  label="收费金额" prop="money">
          <el-input :disabled =true v-model="form1.amt" placeholder="请输入收费金额" />
        </el-form-item>
        <el-form-item  label="付款方式" prop="payId">
          <el-select :disabled =true v-model="form1.payId" placeholder="请选择付款方式">
            <el-option
              :disabled =true
              v-for="dict in Paymentmethod"
              :key="dict.id"
              :label="dict.name"
              :value="parseInt(dict.id)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="收款时间" prop="chargeTime">
          <el-date-picker clearable
            :disabled =true
            v-model="form1.payTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择收款时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="退款时间" prop="refundTime">
          <el-date-picker clearable
            v-model="form1.refundTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择退款时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="退款方式" prop="refundId">
          <el-select v-model="form1.refundId" placeholder="请选择退款方式">
            <el-option

              v-for="dict in Paymentmethod"
              :key="dict.id"
              :label="dict.name"
              :value="parseInt(dict.id)"
            ></el-option>
          </el-select>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm1">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-tabs v-model="activeName" @tab-click="handleClick" >
      <el-tab-pane label="常规收费" name="first">
     <!--   <el-col :span="1.5">
          <el-button type="primary"   size="medium" @click="handleAdd" icon="el-icon-share"
            v-hasPermi="" style="margin-bottom: 10px;">收费</el-button>
        </el-col> -->
        <el-table v-loading="loading" :data="chargedataList" @selection-change="handleSelectionChange">
              <!-- <el-table-column type="selection" width="55" align="center" /> -->
         <el-table-column label="收费项名称" align="center" prop="chargeitemName" />
         <el-table-column label="起收日期" align="center" prop="startTime"></el-table-column>
         <el-table-column label="到期日期" align="center" prop="endTime"></el-table-column>
         <el-table-column label="缴费期限" align="center" prop="deadlineTime" ></el-table-column>
         <el-table-column label="单价" align="center" prop="univalence"></el-table-column>
           <el-table-column label="数量" align="center" prop="univalence"></el-table-column>
             <el-table-column label="金额" align="center" prop="univalence"></el-table-column>
            </el-table>
      </el-tab-pane>
      <el-tab-pane label="临时收费" name="second"><el-table v-loading="loading" :data="moneylist" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />

      <el-table-column label="编号" align="center">{{ shop.code }}
      </el-table-column>
      <el-table-column label="客户名称" align="center" >{{ rentalContract.hirerName }}</el-table-column>
      <el-table-column label="收费项目" align="center" prop="chargeitemName">
      </el-table-column>
      <el-table-column label="收费金额" align="center" prop="money" />
      <el-table-column label="收款时间" align="center" prop="chargeTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.chargeTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="付款方式" align="center" prop="payName">
      </el-table-column>
      <el-table-column label="收款人姓名" align="center" prop="chargeUser" />
      <el-table-column label="退款人姓名" align="center" prop="refundUser" />
      <el-table-column label="退款时间" align="center" prop="refundTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.refundTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="退款方式" align="center" prop="refunName" />
      <el-table-column label="状态" align="center" prop="state">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.zhwy_temporarydeposit_state" :value="scope.row.state" />
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="chargeRemark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button :disabled="scope.row.state == 2" size="mini" type="text" icon="el-icon-edit"
            @click="handleUpdate(scope.row)" v-hasPermi="['feeDeposit:temporarydeposit:edit']">退款</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['feeDeposit:temporarydeposit:remove']">打印</el-button>
        </template>
      </el-table-column>
    </el-table></el-tab-pane>
      <el-tab-pane label="收取押金" name="third"><el-table v-loading="loading" :data="moneylist" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />

      <el-table-column label="编号" align="center">{{ shop.code }}
      </el-table-column>
      <el-table-column label="客户名称" align="center" >{{ rentalContract.hirerName }}</el-table-column>
      <el-table-column label="收费项目" align="center" prop="chargeitemName">
      </el-table-column>
      <el-table-column label="收费金额" align="center" prop="money" />
      <el-table-column label="收款时间" align="center" prop="chargeTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.chargeTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="付款方式" align="center" prop="payName">
      </el-table-column>
      <el-table-column label="收款人姓名" align="center" prop="chargeUser" />
      <el-table-column label="退款人姓名" align="center" prop="refundUser" />
      <el-table-column label="退款时间" align="center" prop="refundTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.refundTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="退款方式" align="center" prop="refunName" />
      <el-table-column label="状态" align="center" prop="state">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.zhwy_temporarydeposit_state" :value="scope.row.state" />
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="chargeRemark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button :disabled="scope.row.state == 2" size="mini" type="text" icon="el-icon-edit"
            @click="handleUpdate(scope.row)" v-hasPermi="['feeDeposit:temporarydeposit:edit']">退款</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['feeDeposit:temporarydeposit:remove']">打印</el-button>
        </template>
      </el-table-column>
    </el-table></el-tab-pane>
      <el-tab-pane label="预存款" name="fourth"><el-table v-loading="loading" :data="moneylist" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />

      <el-table-column label="客户名称" align="center" >{{ rentalContract.hirerName }}</el-table-column>
      <el-table-column label="收费项目" align="center" prop="chargeitemName">
      </el-table-column>
      <el-table-column label="收费金额" align="center" prop="amt" />
      <el-table-column label="收款时间" align="center" prop="date" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.chargeTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="付款方式" align="center" prop="payName">
      </el-table-column>
      <el-table-column label="收款人姓名" align="center" prop="chargeUser" />

      <el-table-column label="状态" align="center" prop="state">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.zhwy_temporarydeposit_state" :value="scope.row.state" />
        </template>
      </el-table-column>
      <el-table-column label="单号" align="center" prop="payNo" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button :disabled="scope.row.state == 2" size="mini" type="text" icon="el-icon-edit"
            @click="handleUpdate1(scope.row)" v-hasPermi="['feeDeposit:temporarydeposit:edit']">退款</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['feeDeposit:temporarydeposit:remove']">打印</el-button>
        </template>
      </el-table-column>
    </el-table></el-tab-pane>
    </el-tabs>



    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import {
  listTemporarydeposit,
  getTemporarydeposit,
  delTemporarydeposit,
  addTemporarydeposit,
  updateTemporarydeposit,
} from "@/api/feeDeposit/temporarydeposit1";
import { listChargeitem } from "@/api/feeSettings/chargeitem";
import { listPaymentmethod } from "@/api/feeSettings/paymentmethod";
import { listShops } from "@/api/asset/shops";
import { getShops } from "@/api/asset/shops";
import {getshopId,getAdvancedeposit,updateAdvancedeposit} from "@/api/feeDeposit/advancedeposit";
import {
  getContractByShopId,
  getTemporarydepositByShopId1,
  getTemporarydepositByShopId2,
} from "@/api/feeDeposit/temporarydeposit";
import { listChargedata, getChargedata } from "@/api/feeSettings/chargedata";
export default {
  name: "Temporarydeposit",
  dicts: [
    "zhwy_temporarydeposit_type",
    "sys_user_sex",
    "zhwy_temporarydeposit_state",
  ],

  data() {
    return {
      //常规收费数据列表
      normalDataList:[],
      chargedataList:[],

      queryParams5:{
        pageNum: 1,
        pageSize: 10,
        shopsId:'',
      },

      //收费项
      queryParams2: {
        pageNum: 1,
        pageSize: 10,
        // mode: 5,
        type: 0,
        name: null,
      },
      //   合同数据
            queryParams3: {
              pageNum: 1,
              pageSize: 10,
              shopsId: null,
              type: null,
              hirerId: null,
            },
      //标签页
      activeName: "first",
      //收费项管理
      chargeitemList: [],
      //商铺管理
      shopList: [],
      //商店详情
      moneylist: [],

      shop: {},
      //合同详情
      rentalContract: {},
      //支付项管理
      Paymentmethod: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 临时收费/押金管理表格数据
      temporarydepositList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      open1: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        type: null,
        shopsId: null,
        name: null,
        chargeitemId: null,
        money: null,
        chargeTime: null,
        payId: null,
        chargeUser: null,
        refundUser: null,
        refundTime: null,
        refundId: null,
        state: null,
        chargeRemark: null,
      },
      // 表单参数
      form: {},
      form1:{},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();

  },
  methods: {

    /** 查询收费数据列表 */
    getDataList() {
      this.queryParams5.shopsId=this.form.shopsId;
      console.log(this.queryParams5.shopsId);
      listChargedata(this.queryParams5).then(response => {
        this.chargedataList = response.rows;
        console.log(this.chargedataList);
      });

    },
    //标签页
    handleClick(tab, event) {
     const i= tab.$options.propsData.name;
     if(i=='second'){
        this.money1();
     }
     if(i=='third'){
      this.money2();
     }
     if(i=='fourth'){
      this.money3();
     }
     if(i=='first'){
       this.getDataList();
     }
    },
    /** 查询临时收费/押金管理列表 */
    getList() {
      this.loading = true;
      listTemporarydeposit(this.queryParams).then((response) => {
        this.temporarydepositList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
      listChargeitem().then((response) => {
        this.chargeitemList = response.rows;
      });
      listShops().then((response) => {
        this.shopList = response.rows;
      });

      listPaymentmethod().then((response) => {
        this.Paymentmethod = response.rows;
      });
    },
    getshops() {
      getShops(this.form.shopsId).then((response) => {
        this.shop = response.data;
        this.aa();
        this.getDataList();
      });

    },
    aa(){
      getContractByShopId(this.shop.id).then((response) => {
        this.rentalContract = response.data;
      });
    },
    //临时收费
    money1() {
      // this.$modal.msgSuccess("查询临时收费成功");
      getTemporarydepositByShopId1(this.shop.id).then((response) => {
        this.moneylist = response.data;
      });
      this.getDataList();
    },
    //押金
    money2() {
      // this.$modal.msgSuccess("查询押金成功");
      getTemporarydepositByShopId2(this.shop.id).then((response) => {
        this.moneylist = response.data;
      });

    },
    //预存款
    money3(){
      // this.$modal.msgSuccess("查询预存款成功");
      getshopId(this.shop.id).then((response) => {
        this.moneylist = response.data;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.open1 = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        type: null,
        shopsId: null,
        name: null,
        chargeitemId: null,
        money: null,
        chargeTime: null,
        payId: null,
        chargeUser: null,
        refundUser: null,
        refundTime: null,
        refundId: null,
        state: null,
        chargeRemark: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.form.type = 0;
      this.open = true;
      this.title = "添加临时收费/押金管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.title = "押金/临时收费款退款管理";
      this.open = true;
      const id = row.id || this.ids;
      //押金退款
      getTemporarydeposit(id).then((response) => {
        this.form = response.data;
      });

    },
    /** 修改按钮操作 */
    handleUpdate1(row) {
      this.reset();
      this.title = "预存款退款管理";
      this.open1 = true;
      const id = row.id || this.ids;
        //预存款退款
        getAdvancedeposit(id).then((response) => {
        this.form1 = response.data;
      });
    },
    /** 押金提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateTemporarydeposit(this.form).then((response) => {
              this.$modal.msgSuccess("退款");
              this.open = false;
              this.getList();
            });
          } else {
            addTemporarydeposit(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 预存款提交按钮 */
    submitForm1() {
            updateAdvancedeposit(this.form1).then((response) => {
              this.$modal.msgSuccess("退款");
              this.open1 = false;
              this.getList();
            });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$modal.msgSuccess("打印成功");
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "feeDeposit/temporarydeposit/export",
        {
          ...this.queryParams,
        },
        `temporarydeposit_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style>
.my-label {
  background: #e1f3d8;
}

.my-content {
  background: #fde2e2;
}
</style>
